package com.study.scala

import java.io.PrintWriter  
import scala.reflect.io.Directory  
import java.util.Date
import java.text.SimpleDateFormat

trait Logged{
     def log(msg: String){}
}
trait ConsoleLogger extends Logged{
    override def log(msg: String)  { 
      println(msg) 
      }
}

trait TimerLogger extends Logged{
    override def log(msg: String)  { 
      println("date:" +new SimpleDateFormat("yyyymmdd").format(new Date()))
    }
}
trait ShortLogger extends Logged{
    var maxLength:Int=15;
    override def log(msg: String)  {
      super.log(
          if(msg.length()<=maxLength)
        msg else msg.substring(0, maxLength));
    }
}
trait Account{
  var banlance:Double=1000;
  def withdraw(amount: Double)
}
class SavingsAccount extends Account with ConsoleLogger {
    def withdraw(amount: Double) {
        if (amount > banlance){
          log("Insufficient funds")
        }else{
          banlance = banlance-amount;
          log("******已经取出******")
        }
    }
}

case class User(name: String, password: String)
/*class Test {
}
object Test {
  def main(args: Array[String]): Unit = {
    val user = new User("zhaosc", "1234")
    def constructor(u: User) = user match {
      //构造器模式必须将User类定义为case class,否则需要自己定义伴生对象并实现unapply方法。
      case User(name, password) => "name =" + name + ",password =" + password
      case _ => "Other"
    }
    println(constructor(user))
  }
}*/